package com.ruoyi.web.controller.safe;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.RiskPreSys;
import com.ruoyi.safe.service.IRiskPreSysService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风险防范体系Controller
 * 
 * @author yxf
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/safe/against")
public class RiskPreSysController extends BaseController
{
    @Autowired
    private IRiskPreSysService riskPreSysService;

    /**
     * 查询风险防范体系列表
     */
    @PreAuthorize("@ss.hasPermi('safe:against:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskPreSys riskPreSys)
    {
        startPage();
        List<RiskPreSys> list = riskPreSysService.selectRiskPreSysList(riskPreSys);
        return getDataTable(list);
    }

    /**
     * 导出风险防范体系列表
     */
    @PreAuthorize("@ss.hasPermi('safe:against:export')")
    @Log(title = "风险防范体系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RiskPreSys riskPreSys)
    {
        List<RiskPreSys> list = riskPreSysService.selectRiskPreSysList(riskPreSys);
        ExcelUtil<RiskPreSys> util = new ExcelUtil<RiskPreSys>(RiskPreSys.class);
        return util.exportExcel(list, "风险防范体系数据");
    }

    /**
     * 获取风险防范体系详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:against:query')")
    @GetMapping(value = "/{rpsId}")
    public AjaxResult getInfo(@PathVariable("rpsId") Long rpsId)
    {
        return AjaxResult.success(riskPreSysService.selectRiskPreSysById(rpsId));
    }

    /**
     * 新增风险防范体系
     */
    @PreAuthorize("@ss.hasPermi('safe:against:add')")
    @Log(title = "风险防范体系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskPreSys riskPreSys)
    {
        return toAjax(riskPreSysService.insertRiskPreSys(riskPreSys));
    }

    /**
     * 修改风险防范体系
     */
    @PreAuthorize("@ss.hasPermi('safe:against:edit')")
    @Log(title = "风险防范体系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskPreSys riskPreSys)
    {
        return toAjax(riskPreSysService.updateRiskPreSys(riskPreSys));
    }

    /**
     * 删除风险防范体系
     */
    @PreAuthorize("@ss.hasPermi('safe:against:remove')")
    @Log(title = "风险防范体系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rpsIds}")
    public AjaxResult remove(@PathVariable Long[] rpsIds)
    {
        return toAjax(riskPreSysService.deleteRiskPreSysByIds(rpsIds));
    }
}
